import ctypes
import os,shutil,io
import sys

bmp_path=r"C:\Users\twy\PycharmProjects\房产局\zp.bmp"
copy_path=r"D:\image\用户"
ter_dll = ctypes.windll.LoadLibrary("Termb.dll")
def readcard(n_name):
    iPort = 1001
    while True:
        iRet = ter_dll.CVR_InitComm(iPort)
        if iRet == 1:
            ret = ter_dll.CVR_Authenticate()
            if ret == 1 :
                ter_dll.CVR_Read_FPContent()
                if ter_dll.CVR_Read_FPContent()==1:
                    with open("wz.txt", "r") as f:
                        data = f.readlines()
                        print(data[0].strip())
                        copy(n_name)
                        return 0
                ter_dll.CVR_CloseComm()
def copy(n_name):
    n_name=n_name+".bmp"
    if os.path.exists(bmp_path):  # 判断文件是否存在，以防中间序列不连续
        shutil.copy(bmp_path,copy_path)
        os.chdir(copy_path)
        try:
            os.rename("zp.bmp", n_name)
        except:
            print("名字重复")
if __name__ == '__main__':
    readcard("叫我小唐就好了（开心版）")
